<template>
  <div>设置密码</div>

  <div>
    <van-form @submit="onSubmit">
      <van-cell-group inset>
        <van-field
          v-model="password"
          type="password"
          name="password"
          label="密码"
          placeholder="密码"
          :rules="[
            { required: true, message: '请填写密码' },

            { pattern, message: '请输入正确的密码2-8位' },
          ]"
        />
      </van-cell-group>
      <div style="margin: 16px">
        <van-button round block type="primary" native-type="submit">
          提交
        </van-button>
      </div>
    </van-form>
  </div>
</template>

<script setup lang="ts">
import { getFinishRegister } from '@/apis/user'
import { ref } from 'vue'

import { useUserStore } from '@/store/userStore'

import { useRouter } from 'vue-router'
const user = useUserStore()
const router = useRouter()

const pattern = /^.{2,8}$/
const password = ref('')

const onSubmit = async (values) => {
  // 需要两个  电话和密码  
  // 1 如何获取电话   从pinia里面获取
  // 2  密码  password.vaule

  // 3  发送请求  注册成功了 跳转到登录页面进行登录
  //   password
  // :
  // "222"
  // tel
  // :
  // "18812342341"

  let res = await getFinishRegister({ tel: user.tel, password: password.value })

  console.log(res)

  if (res.code === '200') {
    router.push('/login')
  }
}
</script>

<style scoped></style>
